Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

feat: add oclif pretty printer #27

Merged
merged 15 commits into from
Jun 25, 2020
Merged

feat: add oclif pretty printer #27

merged 15 commits into from
Jun 25, 2020

Conversation

chadian
Copy link
Contributor

@chadian chadian commented Jun 1, 2020

closes #28

Adds a prettyPrint function along with an PrettyPrintableInterface with the interface it works with. This is used in the handle function in place of using render methods on Error objects. Pulling out the rendering of an error to a function and not having it be based on an error method allows the prettyPrint function to be used at any point by oclif developers (ie: in a command instance's catch method). It also allows different classes of errors to be pretty printed.

@chadian chadian force-pushed the pretty-print-errors branch 3 times, most recently from e1ec000 to cdb0028 Compare June 4, 2020 19:26
@chadian chadian changed the title Add oclif pretty printer feat: add oclif pretty printer Jun 4, 2020
@chadian chadian force-pushed the pretty-print-errors branch 3 times, most recently from 1a49ffe to abd450a Compare June 5, 2020 17:50
@chadian chadian requested a review from RasPhilCo June 5, 2020 18:02
src/handle.ts Outdated Show resolved Hide resolved
src/handle.ts Outdated Show resolved Hide resolved
src/index.ts Outdated Show resolved Hide resolved
@chadian chadian force-pushed the pretty-print-errors branch 2 times, most recently from db79e25 to 4c56cfc Compare June 17, 2020 17:42
Copy link
Contributor

@RasPhilCo RasPhilCo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏄

Copy link
Contributor

@RasPhilCo RasPhilCo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏄

@chadian chadian force-pushed the pretty-print-errors branch from 41a87bc to fb4718a Compare June 24, 2020 15:29
@chadian chadian force-pushed the pretty-print-errors branch from cb22dbb to b0672bb Compare June 24, 2020 21:54
@chadian chadian merged commit 27f8bb5 into master Jun 25, 2020
@chadian chadian deleted the pretty-print-errors branch June 25, 2020 14:26
/**
* a suggestion that may be useful or provide additional context
*/
suggestion?: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* a url to find out more information related to this error
* or fixing the error
*/
ref?: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

// and is like either Error or Warning
const formattedHeader = message ? `${errorSuffix || 'Error'}: ${message}` : undefined
const formattedCode = code ? `Code: ${code}` : undefined
const formattedSuggestion = suggestion ? `Suggestion: ${suggestion}` : undefined
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Salesforce CLI says "Try this:". I like that a little more than "Suggestion:" but I don't care all that much. It might be worth it to have doc weigh-in. Or I guess to say it another way, if the Salesforce CLI would ever want to use this standard oclif error format, we would want to run it by doc.

*/
export interface OclifError {
oclif: {
exit?: number | false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come this is in an oclif property but the other things like ref, code etc are on the actual error object? I always thought the exitCode should be on the error but a personal opinion.

In any case, this is our error object. Some stuff is specific to Salesforce like labels, but having the properties like actions vs. suggestion would be nice.

Copy link
Contributor Author

@chadian chadian Jun 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was more for backwards compatibility with the existing structure of cli error and the oclif property that was defined prior. Then the handle function expects it. It's unlikely people would have a different version of the @oclif/errors or would be creating their own errors with oclif.exit but we didn't want to risk it. Instead we wanted to call out it as an oclif error concern one that isn't involved with the display of the error. With your exitCode are you using a custom handle function in bin/run, too?

@erezrokah
Copy link

FYI this was a breaking change as fs-extra@^9 dropped support for node 8:
https://github.com/jprichardson/node-fs-extra/blob/master/CHANGELOG.md#900--2020-03-19

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feat] display more informative error objects
4 participants